package com.kmxd.ams.controller.system;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kmxd.ams.client.system.ISysFondsSvc;
import com.kmxd.ams.client.system.dto.SysFondsAddDTO;
import com.kmxd.ams.client.system.dto.SysFondsEditDTO;
import com.kmxd.ams.client.system.dto.SysFondsQueryDTO;
import com.kmxd.ams.client.system.vo.SysFondsListVO;
import com.kmxd.ams.client.system.vo.SysFondsVO;
import com.kmxd.ams.core.common.enums.LogLevelEnum;
import com.kmxd.ams.core.common.enums.LogTypeEnum;
import com.kmxd.ams.core.log.annotation.AutoLog;
import com.kmxd.ams.core.result.R;
import com.kmxd.ams.core.util.SecurityUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 全宗 前端控制器
 *
 * @since 2022-07-14
 * @author ZuoLG
 */
@RestController
@Tag(name = "全宗管理")
@RequestMapping("/system/sysFonds")
@AllArgsConstructor
public class SysFondsCtl {

  private ISysFondsSvc sysFondsService;

  /** 分页查询 */
  @Operation(summary = "分页查询")
  @GetMapping("/selectPage")
  @SaCheckLogin
  @AutoLog(module = "全宗", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "分页查询")
  public R<Page<SysFondsListVO>> selectPage(Page reqPage, SysFondsQueryDTO req) {
    req.setComId(ObjectUtil.isNotEmpty(req.getComId()) ? req.getComId() : SecurityUtil.getCropId());
    return R.success(sysFondsService.selectPage(reqPage, req));
  }
  /** 列表查询 */
  @Operation(summary = "列表查询")
  @GetMapping("/list")
  @SaCheckLogin
  @AutoLog(module = "全宗", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "分页查询")
  public R<List<SysFondsListVO>> list(SysFondsQueryDTO req) {
    req.setComId(ObjectUtil.isNotEmpty(req.getComId()) ? req.getComId() : SecurityUtil.getCropId());
    return R.success(sysFondsService.list(req));
  }

  /** 新增 */
  @Operation(summary = "新增")
  @PostMapping("/add")
  @SaCheckPermission("system:sysFonds:add")
  @AutoLog(module = "全宗", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "新增")
  public R<Void> add(@Validated @RequestBody SysFondsAddDTO req) {
    sysFondsService.add(req);
    return R.success();
  }

  /** 修改 */
  @Operation(summary = "修改")
  @PostMapping("/edit")
  @SaCheckPermission("system:sysFonds:edit")
  @AutoLog(module = "全宗", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.HIGH, title = "修改")
  public R<Void> edit(@Validated @RequestBody SysFondsEditDTO req) {
    sysFondsService.edit(req);
    return R.success();
  }

  /** 删除 */
  @Operation(summary = "删除")
  @PostMapping("/remove")
  @SaCheckPermission("system:sysFonds:remove")
  @AutoLog(module = "全宗", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.HIGH, title = "删除")
  public R<Void> remove(@RequestParam String ids) {
    sysFondsService.remove(ids);
    return R.success();
  }

  /** 查看 */
  @Operation(summary = "查看")
  @GetMapping("/view")
  @AutoLog(module = "全宗", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "查看")
  public R<SysFondsVO> view(@RequestParam Long id) {
    return R.success(sysFondsService.view(id));
  }

  /** 获取自动增加排序 */
  @Operation(summary = "获取自动增加排序")
  @PostMapping("/getAutoIndex")
  @AutoLog(module = "全宗-获取自动增加排序", type = LogTypeEnum.SYSTEM, title = "获取自动增加排序")
  public R<Integer> getAutoIndex() {
    return R.success(sysFondsService.getAutoIndex());
  }
}
